<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;

class CheckEnterParams
{
    /**
     * 检测入口 openID 
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle(Request $request, Closure $next)
    {
        //入口是否必须带 openid 参数
        if(config('visit.enter_with_openid')){
            if($request->has('uopenid')){
                return $next($request);
            }
            else{
                return errorGo('errorfrom');
            }
        }
        //是否只能微信访问
        if(config('visit.wechat_visit_only')){
            $ua = $_SERVER['HTTP_USER_AGENT'];
            if(strpos($ua, 'MicroMessenger') == false){ 
                //非微信内置浏览器
                return errorGo('nowechat');
            }
        }
        return $next($request);
    }
}
